package store.lunangangster.bpmn.converter.parser;

import javax.xml.stream.XMLStreamReader;
import store.lunangangster.bpmn.model.BaseElement;
import store.lunangangster.bpmn.model.BpmnModel;
import store.lunangangster.bpmn.model.Event;
import store.lunangangster.bpmn.model.definition.TimerEventDefinition;

public class TimerEventDefinitionParser extends BaseChildElementParser {

  public TimerEventDefinitionParser() {
    addChildElementParser(new TimeDateParser());
    addChildElementParser(new TimeDurationParser());
    addChildElementParser(new TimeCycleParser());
  }

  @Override
  public String getTargetName() {
    return EVENT_DEFINITION_TIMER;
  }


  @Override
  public void parseChild(XMLStreamReader xsr, BaseElement parentElement, BpmnModel model)
      throws Exception {
    if (parentElement instanceof Event) {
      TimerEventDefinition timerEventDefinition = new TimerEventDefinition();
      ((Event) parentElement).getEventDefinitions().add(timerEventDefinition);

      parseChildElement(xsr, timerEventDefinition, getTargetName(), model);
    }
  }
}
